﻿package com.ufenlei.LTS{
	import flash.events.Event;
	
	public class RadioGroup extends Input{
		protected var _label:String;
		protected var _radioList:Array = new Array();
		protected var _bottom:int;
		protected var _checkdIndex:uint = 0;
		public function RadioGroup(de:Boolean = false, 
								   lck:Boolean = false){
			super(de,lck);
		}
		public function addRadio(rLabel:String,rIdx:int):void{
			var op:RadioBox = new RadioBox(rLabel,_radioList.length);
			op.addEventListener(Input.SELECTED, onRadioSelected);
			_bottom += (this._bottom > 0.1)?5:0;
			_radioList.push(op);
			op.y = this._bottom;
			this.addChild(op);
			this._bottom += op.height;
		}
		public function get idx():uint{
			return _checkdIndex;
		}
		protected function onRadioSelected(evt:Event):void{	
			if(_checkdIndex !== evt.target.idx ){
				_radioList[_checkdIndex].unselect();
				_checkdIndex = evt.target.idx;
				dispatchChangeEvent();
			}
		}
		override public function lock():void{
			if(enableListening){
				this.enableListening = false;
				for each(var radio:RadioBox in _radioList){
					radio.lock();
				}
			}
		}
		override public function unlock():void{
			if(!enableListening){
				enableListening = true;
				for each(var radio:RadioBox in _radioList){
					radio.unlock();
				}
			}
		}
		private function dispatchChangeEvent():void{
			dispatchEvent(new Event(Input.CHANGE));
		}
	}
}